/**
 * strategies
 */


  var tool = require("../tool");
  var consts = require("../../consts/consts");
  var defaultErrors = require("./defaultErrors");
  var validators = {
      isValidMobile: function (value, error){
          if (value.length && !(/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(value))){
              return error || defaultErrors["mobile"];
          }
      },
      isValidUrl: function (value, error){
          var urlReg = /^(((http|https):\/\/)|((http|https):\/\/www\.)|(www\.))(([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.)([0-9a-z]{2,6}.)?((([0-9a-z]{2,6}.)(com|cn|hk|(com\.cn)))|(com|cn|hk|(com\.cn)))(\/)*([\s\S]*)$/;
          var result = urlReg.test(value);
          if (value.length && !result){
              return error || defaultErrors["url"];
          }
      },
      isNonEmpty: function (value, error){
          if (!value.length){
              return error || defaultErrors["empty"];
          }
      },
      isMinLength: function (value, error, length){
          if (value.length < length){
              return error || defaultErrors["min"](length);
          }
      },
      isMaxLength: function (value, error, length){
          if (value.length > length){
              return error || defaultErrors["max"](length);
          }
      },
      isValidJdUrl: function(value, error){
          if (value.length && (value.indexOf('jd.com') == -1 && value.indexOf('jd.hk') == -1)){
              return error || defaultErrors["shopperUrl"];
          }
      },
      isValidTmUrl: function(value, error){
          if (value.length && value.indexOf('tmall.com') == -1){
              return error || defaultErrors["shopperUrl"];
          }
      },
      isValidTbUrl: function(value, error){
          if (value.length && value.indexOf('taobao.com') == -1){
              return error || defaultErrors["shopperUrl"];
          }
      },
      isValidSnUrl: function(value, error){
          if (value.length && value.indexOf('suning.com') == -1){
              return error || defaultErrors["shopperUrl"];
          }
      },
      isValidPhone: function(value, error){
          if (value.length && !(/^[0-9]*$/g.test(value))){
              return error || defaultErrors["Phone"];
          }
      },
      isValidTemplatePhone: function (value, error){
          if (value.length && (!(/^[0-9]*$/g.test(value)) || value.length > 21)){
              return error || defaultErrors["Phone"];
          }
      },
      isValidIosUrl: function(value, error){
          if (value.length && !(/(itunes\.apple\.com\/|apple\.com\/itunes).*id[0-9]{5,10}/.test(value))){
              return error || defaultErrors["downIosUrl"];
          }
      },
      isValidAndUrl: function (value, error){
          if (value.length && !(/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g.test(value))){
              return error || defaultErrors["downAndUrl"];
          }
      },
      isValidVideoUrl: function (value, error){
          if (value.length && (value.indexOf("v.qq.com") == -1 && value.indexOf("v.youku.com") == -1) && value.indexOf("www.tudou.com") == -1){
              return error || defaultErrors["video"];
          }
      },
      isValidOffset: function (value, error){
          if (value < -consts.RANGE.OFFSET || value > consts.RANGE.OFFSET){
              return error || defaultErrors["offset"](consts.RANGE.OFFSET);
          }
      },
      isValidRotate: function (value, error){
          if (value < -consts.RANGE.ROTATE || value > consts.RANGE.ROTATE){
              return error || defaultErrors["rotate"](consts.RANGE.ROTATE);
          }
      },
      isValidNonDecimal: function (value, error){
          if (tool.isDecimal(value)){
              return error || defaultErrors["nonDecimal"];
          }
      },
      isValidSize: function (value, error){
          if (value < consts.RANGE.SIZE.MIN || value > consts.RANGE.SIZE.MAX){
              return error || defaultErrors["size"](consts.RANGE.SIZE.MIN, consts.RANGE.SIZE.MAX);
          }
      },
      isValidOpacity: function (value, error){
          if (value < consts.RANGE.OPACITY.MIN || value > consts.RANGE.OPACITY.MAX){
              return error || defaultErrors["opacity"](consts.RANGE.OPACITY.MIN, consts.RANGE.OPACITY.MAX);
          }
      },
      isValidScale: function (value, error){
          if (!parseInt(value) || !parseFloat(value)){
              return error;
          }
      },
      isValidLight: function (value, error){
          if (!parseFloat(value)){
              return error;
          }
      },
      isValidLabel: function (value, error){

      },
      isValidColor: function (value, error){
          if (value.length && !(/^[0-9a-fA-F]{6}$/g.test(value))){
              return error || defaultErrors["color"];
          }
      },
      isValidText: function (value, error){
          if (!value.length){
              return error || defaultErrors["text"];
          }
      },
      isValidRadius: function(value, error){
          if (parseFloat(value)　< 0){
              return error || defaultErrors["radius"];
          }
      },
      isValidTipText: function (value, error){

      },
      isValidDateRange: function (startValue, endValue, spliter, error){
          spliter = spliter || "-";

          var reg = new RegExp(spliter, "ig");
          if (startValue && endValue){
              startValue = startValue.replace(reg, "");
              endValue = endValue.replace(reg, "");

              startValue = parseInt(startValue);
              endValue = parseInt(endValue);

              if (startValue > endValue){
                  return error || defaultErrors["dateRange"];
              }
          }
      }
  };

  module.exports = validators;
